//
//  NYChoseBookView.m
//  NiuWaJiaoYu
//
//  Created by MinLison on 2017/12/4.
//  Copyright © 2017年 niuwaketang. All rights reserved.
//

#import "NYChoseBookView.h"

#import "NYSearchViewController.h"

@implementation NYChoseBookView

- (void)setupView
{
    [super setupView];
    [self configSubViews];
}


- (void)setGradeView:(UIView *)gradeView {
    _gradeView = gradeView;
    
    gradeView.qmui_borderPosition = QMUIBorderViewPositionRight;
    gradeView.qmui_shadowColor = UIColorHex(0xe6e6e6);
    gradeView.qmui_shadowOpacity = 1;
    [self configSubViews];
}
- (void)setItemView:(UIView *)itemView {
    _itemView = itemView;
    [self configSubViews];
}
- (void)configSubViews
{
    if (!self.gradeView || !self.itemView) {
        return;
    }
    UIView *contentView = [[UIView alloc] init];
    [contentView addSubview:self.gradeView];
    [contentView addSubview:self.itemView];
    [self addSubview:contentView];
    
    [contentView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        if (@available(iOS 11.0,*))
        {
            make.top.equalTo(self.mas_safeAreaLayoutGuideTop);
            make.left.equalTo(self.mas_safeAreaLayoutGuideLeft);
            make.right.equalTo(self.mas_safeAreaLayoutGuideRight);
        }
        else
        {
            make.top.equalTo(self.controller.mas_topLayoutGuideBottom);
            make.left.right.equalTo(self);
        }
        if (@available(iOS 11.0,*))
        {
            make.bottom.equalTo(self.mas_safeAreaLayoutGuideBottom);
        }
        else
        {
            make.bottom.equalTo(self);
        }
    }];
    
    
    [self.gradeView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.left.bottom.equalTo(contentView);
        make.width.mas_equalTo(__WGWidth(100));
    }];
    [self.itemView  mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.gradeView.mas_right);
        make.top.right.bottom.equalTo(contentView);
    }];
    
}

- (void)goToTheSearchViewController {
        
    [self.controller.navigationController pushViewController:[NYSearchViewController new] animated:true];
}

- (UIView *)configNavgationSearchView {
        UIView *searchView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH -  __WGWidth(139), 28.f)];
        [searchView setBackgroundColor:UIColorMakeWithHex(@"#FFFFFF")];
        UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:searchView.bounds byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(14.f, 14.f)];
        CAShapeLayer *maskLayer = [CAShapeLayer layer];
        maskLayer.frame = searchView.bounds;
        maskLayer.lineCap = kCALineCapRound;
        maskLayer.lineJoin = kCALineJoinRound;
        maskLayer.path = path.CGPath;
        searchView.layer.mask = maskLayer;
    
        UILabel *keyLabel = [[UILabel alloc] initWithFrame:CGRectMake(19, 0, 100, 28.f)];
        keyLabel.font = UIFontMake(14);
        keyLabel.textColor = UIColorMakeWithHex(@"#D0D0D0");
        keyLabel.text = @"输入课程关键词";
        [searchView addSubview:keyLabel];
        
        UIImageView *searImgView = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectGetWidth(searchView.frame) - 31, 6.5f, 15, 15)];
        searImgView.image = [UIImage sou_suo];
        [searchView addSubview:searImgView];
    
//    [keyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//
//        make.left.equalTo(searchView).offset(19);
//        make.top.bottom.equalTo(searchView);
//        make.width.mas_equalTo(100.f);
//    }];
//    [searImgView mas_makeConstraints:^(MASConstraintMaker *make) {
//
//        make.right.equalTo(searchView).offset(-15);
//        make.centerX.equalTo(searchView);
//        make.width.height.mas_equalTo(15);
//    }];

        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(goToTheSearchViewController)];
        tap.cancelsTouchesInView = false;
        [searchView addGestureRecognizer:tap];
        return searchView;
}

@end
